var express = require('express');
var router = express.Router();
const path = require('path');
const db = require('../lib/mongo')
const update = require('../lib/mqtt_fun')


router.get('/', function (req, res, next) {
  res.sendFile(path.join(__dirname, 'dist/index.html'));
});

router.post('/querysensor', async function (req, res, next) {
  const obj = req.body;
  console.log(obj);
  const resuld = await db.run(obj);
  res.send(resuld)

});

router.post('/updateparam', function (req, res, next) {
  const obj = req.body;
  // console.log(obj.params);
  update(obj.params);
  // res.send(rev);
});

module.exports = router;